<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    <meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>编辑房间数据</title>
    <meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	
	<link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/vivo.css">
    <link rel="stylesheet" href="css/cmxform.css">
    <link rel="stylesheet" href="js/grid/bsgrid.all.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="js/Hui-iconfont/1.0.7/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="js/icheck/icheck.css" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
	<link rel="stylesheet" href="js/grid/bsgrid.all.min.css"/>
	
	<script src="js/jquery-1.11.1.js"></script>
	<link rel="stylesheet" href="js/uploadify/uploadify.css" type="text/css">
	<script type="text/javascript" src="js/uploadify/jquery.uploadify.min.js"></script>
	<script type="text/javascript" src="js/form.js"></script>
    <script src="js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="js/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <script type="text/javascript" src="js/layer/layer/layer.js"></script> 
    <link href="js/select2/select2.min.css" type="text/css" rel="stylesheet" />
	<script src="js/select2/select2.min.js"></script>
    <script type="text/javascript" src="js/sharefunction.js"></script>
    <script language="javascript" type="text/javascript" src="<%=basePath %>js/My97DatePicker/WdatePicker.js"></script>
	
    <script type="text/javascript">

    $.validator.setDefaults({
		submitHandler: function(){
			saveDocument();
    	}
    });
    $(document).ready(function() {
    	initUploadMulti("<%=basePath %>");
    	$("#leaseState").select2({minimumResultsForSearch:-1});
		$("#archiveState").select2({minimumResultsForSearch:-1});
		$("#sortNum").select2({minimumResultsForSearch:-1});
        
    	var val2 = ${roomInfo.archiveState};
    	showPanel2(val2);
    	
		$("#commentForm").validate({
			errorPlacement:function(error,element){
				$(element).next().append(error);
			},
			errorElement:"span",
			messages:{
				roomNumber:{
					required:" 请填写房间号! "
				},
				unitNumber:{
					required:"请填写单元号! "
				},
				coveredArea:{
					number:"请输入数字！ "
				},
				useArea:{
					number:"请输入数字！ "
				}
			}
		});  		
	});
    
  //失去焦点时，验证室号全称是否重复
	function bl(){
		var roomName = $("#roomName").val();
		var Name = $("#Name").val();
		var buildingInfoId = $("#buildingInfoId").val();
   		var url = "project/roomInfo/findRoomName";
   		var flag = onBlur(url,roomName,buildingInfoId);
   		if(Name==roomName){
   			$("#b_tip").text("");
   		}
   		return flag;
	}
  
    function saveDocument(){
    	var Name = $("#Name").val();
		var roomNumber = $("#roomNumber").val();
	   	var unitNumber = $("#unitNumber").val();
	   	var roomName = $("#roomName").val();
	   	var floor = $("#floor").val();
	 	var coveredArea = $("#coveredArea").val();
	 	var useArea = $("#useArea").val();
		var orientations = $("#orientations").val();
		var fkRoomtype = $("#fkRoomtype").val();
		var sortNum = $("#sortNum").val();
		var priceSpan = $("#priceSpan").val();
		var leaseState = $("#leaseState").val();
		var archiveState = $("#archiveState").val();
		var archiveReason = $("#archiveReason").val();
		var id = $("#id").val();
		var deviceRemark = $("#deviceRemark").val();
	 	var attids = $("#attids").val();
	 	if(bl()==false&&Name!=roomName){
   			return;
   		}
		//layer.confirm("确定修改吗？",{icon:3},function(i){
			var url="project/roomInfo/edit";
			jQuery.ajax({
			    type:"post",
			    async:false,
			    url:url,
		        dataType:"json",
		        data:{
					roomNumber:roomNumber,
					unitNumber:unitNumber,
					roomName:roomName,
					floor:floor,
					scoveredArea:coveredArea,
					suseArea:useArea,
					orientations:orientations,
					fkRoomtype:fkRoomtype,
					sortNum:sortNum,
					priceSpan:priceSpan,
					leaseState:leaseState,
					archiveState:archiveState,
					archiveReason:archiveReason,
					id:id,
					deviceRemark:deviceRemark,
					attids:attids
		        },
			    success:function(data){
			        if(data.success){
				    		window.parent.layer.msg('保存成功！');
							window.parent.gridObj.refreshPage();
							closeLayer();
			        	}else{
			        		layer.alert(data.msg,{icon:7});
			        	}
			    }
	   		});
		//});
    }

	function showPanel(val){
		if(val=="1"){
			$("#panel10").show();
		}else{
			$("#panel10").hide();
		}
	}
	function showPanel2(val2){
		if(val2==true){
			$("#panel10").show();
		}else{
			$("#panel10").hide();
		}
	}

	
	function show1(val){
		var roomName = $("#roomName").val();
		var room = roomName.split("-");
		var roomNumber = $("#roomNumber").val();
		$("#roomName").val(room[0]+"-"+room[1]+"-"+roomNumber);
	}
	function show2(val){
		var roomName = $("#roomName").val();
		var room = roomName.split("-");
		//var roomNumber = $("#roomNumber").val();
		var unitNumber = $("#unitNumber").val();
		$("#roomName").val(room[0]+"-"+unitNumber+"-"+room[2]);
	}	
	


    </script>
	
	
  </head>
  
  <body>
  	<form class="cmxform" id="commentForm" method="get" action="">
  		<div style="padding:20px">
			 <div class="panel panel-default">
			 	<div class="panel-heading">
      				<h5 class="panel-title">房间信息</h5>
   			  	</div>
			   <div class="panel-body">
			   
				  
					<table cellpadding="10" cellspacing="5" class="mytable">
						<tr>
							<td width="90">房间号</td>
							<td width="310">
							<input type="text" name="roomNumber" id="roomNumber"  onchange="show1(this.value)" value="${roomInfo.roomNumber}" required onblur="bl()"/><font color="red"> *</font>
							<span></span>
							</td>
							<td width="90">单元号</td>
							<td><input type="text" id="unitNumber" name="unitNumber" onchange="show2(this.value)" value="${roomInfo.unitNumber}" required  onblur="bl()"/><font color="red"> *</font>
							<span>如无单元则填写0</span> 
							</td>
						</tr>
						
						<tr>
							<td >室号全称</td>
							<td><input type="text" name="roomName" id="roomName" value="${roomInfo.roomName}" readonly/>
							 	<span style="color:red" id="b_tip"></span>
							 </td>
							<td >所在楼层</td>
							<td><input type="text" name="floor" id="floor" value="${roomInfo.floor}"/>
							</td>
						</tr>
						
						<tr>
							<td>建筑面积</td>
							<td><input type="text" name="coveredArea" id="coveredArea" value="${roomInfo.coveredArea}" class="number"/> ㎡ 
							<span style="color:red"></span>
							</td>
							<td>使用面积</td>
							<td><input type="text" name="useArea" id="useArea" value="${roomInfo.useArea}" class="number"/> ㎡
							<span style="color:red"></span>
							</td>
						</tr>
						<tr>
							<td>朝向</td>
							<td><input type="text" name="orientations" id="orientations" value="${roomInfo.orientations}" /> </td>
							<td>房型</td>
							<td><input type="text" name="fkRoomtype" id="fkRoomtype" value="${roomInfo.fkRoomtype}"  placeholder="如：两室一厅/三室一厅"/> </td>
						</tr>
						<tr>
							<td>房间性质</td>
							<td>
							<%--<input type="text" name="sortNum" id="sortNum" value="${roomInfo.sortNum}"  placeholder="如：写字楼/商铺/住宅"/>
							--%>
								<select class="js-example-basic-single" name="sortNum" id="sortNum" style="width:70px;">
									<c:choose>
										<c:when test="${roomInfo.sortNum == '0'}">
											<option value="0" selected>写字楼</option>
											<option value="1">商铺</option>
											<option value="2">住宅</option>
										</c:when>
										<c:when test="${roomInfo.sortNum == '1'}">
											<option value="0">写字楼</option>
											<option value="1" selected>商铺</option>
											<option value="2">住宅</option>
										</c:when>
										<c:when test="${roomInfo.sortNum == '2'}">
											<option value="0">写字楼</option>
											<option value="1">商铺</option>
											<option value="2" selected>住宅</option>
										</c:when>
									</c:choose>
								</select>
							 </td>
							<td>租售状态</td>
			   				<td>
			   					<select name="leaseState" id="leaseState" style="width:70px;">
			   						<c:choose>
			   							<c:when test="${roomInfo.leaseState==false}">
			   								<option value="0" selected>出租</option>
			   								<option value="1">已售</option>
			   							</c:when>
			   							<c:otherwise>
			   								<option value="0" >出租</option>
			   								<option value="1" selected>已售</option>
			   							</c:otherwise>
			   						</c:choose>
				    				
			   					</select>
			   				</td>
						</tr>
						<tr>
		   					
			   				<td>归档状态</td>
			   				<td>
			   					<select name="archiveState" id="archiveState" onchange="showPanel(this.value);" style="width:70px;">
				    				<c:choose>
										<c:when test="${roomInfo.archiveState==false }">
				                    		<option value="0" selected>正常</option>
				   							<option value="1">已归档</option>
				                        </c:when>
										<c:otherwise>
											<option value="0" >正常</option>
				   							<option value="1" selected>已归档</option>
										</c:otherwise>
									</c:choose>
		    					</select>
			   					
			   				</td>
	    				</tr>
		   			<tr>
	    				<td>设备信息</td>
	    				<td>
	    					<textarea rows="3" cols="32" style="width:178%" name="deviceRemark" id="deviceRemark">${roomInfo.deviceRemark}</textarea>
	    				</td>
	    			</tr>
	    			<tr>
	    				<td>房间平面图</td>
	    				<td colspan="3">
	    				<input class="uploadify" attType="file1" id="uploadify" name="uploadify" type="file"/><span id="uploadifyInfo" attType="file1"></span>
	    				(请上传图片)
	    					
	    				</td>
    				</tr>
			   			<tr id="panel10" style="display:none">
	    				<td>归档的原因</td>
	    				<td>
	    				<textarea rows="3" cols="32" style="width:178%" name="archiveReason" id="archiveReason">${roomInfo.archiveReason }</textarea>
	    				</td>
			   			</tr>
					</table>
				</div>
			</div>
			 
			
			<div style="width:100%;text-align:center;padding-top:20px" > 
				 <button class="btn btn-primary" type="submit"> 保 存 </button> &nbsp; 
				 <button type="reset" class="btn btn-default" onClick="closeLayer();"> 取 消 </button> 
		    	  <br/><br/>
	    	</div> 
	    	
	    	<div style='display:none;'>
	    		<input type="text" id="id" name="id" value="${roomInfo.id}"/>
	    		<input type="text" name="Name" id="Name" value="${roomInfo.roomName}" readonly/>
	    	</div>
			<jsp:include page="/upload-field.jsp"></jsp:include>
		</div>
	</form>
   	
  </body>
</html>
